﻿<!DOCTYPE html>
<html>
<#include "include/header.html"/>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<body>
<div class="page">
	<div class="content m">
		
		<div class="cart_confirm">
		<#list commodityList as a>
			<div class="item">
			<#if a.commodity_logo??>
				<img src="${server_uri!}${a.commodity_logo!}" class="pic">
				<#else>
				<img src="" class="pic">
				</#if>
				<div class="title">${a.commodity_name!}</div>
				<#if commodity_type == '01' >
				<div class="price">￥${a.commodity_price!}</div>
				<#else>
				<div class="price">￥1</div>
		        </#if>
				
				<div class="attr">型号:${a.version_type!}</div>
				<#if commodity_type == '01' >
                 <div class="attr">数量:${a.countNum!}</div>				
                 <#else>
				<div class="attr">人次:${a.countNum!}</div>
		        </#if>
				
			</div>
			</#list>
		</div>
		<#if commodity_type == '01' >
	<#if sendAddress??>
		<div class="mod_addr">
			<div class="t">送至</div>
			<div class="address">${sendAddress.province_name!}${sendAddress.city_name!}${sendAddress.country_name!}${sendAddress.geography_location!}</div>
			<div class="name">${sendAddress.receiver_name!}${sendAddress.telephone!}</div>
		</div>
		<#else>
		<div class="mod_addr">
			<div class="t">送至</div>
			<div class="address"></div>
			<div class="name"></div>
		</div>
		</#if>
		</#if>
		<#if commodity_type == '01' >
		<div class="mod_attr">
			<div class="item">
				<div class="fl">配送方式</div>
				<div class="fr fr_">商家配送</div>
			</div>
		</div>
		</#if>
		<div class="mod_attr mod_large">
			<div class="item">
				<div class="fl">商品总额</div>
				<div class="fr fr_">￥<span class="red" >${total_price!}</span></div>
			</div>
			<#if commodity_type == '01' >
			<div class="item" id="yunfei">
			</div>
			</#if>
		</div>	
		<#if (ptrList?size>0)>
		<div class="mod_attr mod_large">
			<h1 class="item title">选择优惠券</h1>
			<div class="item">
			<#list ptrList as ptr >
				<div class="ticket" data-id="${ptr.id!}" data-value="${ptr.mortgage_amount!}"> <!--选中的加checked-->
					<div class="content">
						<strong>${ptr.mortgage_amount!}</strong>
						<div class="info">
							<h2>满${ptr.minimum_threshold_amount!}立减${ptr.mortgage_amount!}元</h2>
							<h3>有效期：${ptr.df_begin_date!}-${ptr.df_end_date!}</h3>
						</div>
					</div>
				</div>
			</#list>
			</div>
		</div>
		</#if>				
	</div>

	<div class="footer">
		<div class="btn_group tab_c tab_c1">
			<div class="total" style="font-size:20px;">合计：￥<span id="totalPrice"></span></div>
			<a href="javascript:void(0);" class="btn btn_red btn_submit" onclick="submitOrder();">提交订单</a>
		</div>
	</div>
	
</div>
</body>
<script type="text/javascript">
$(function(){
var price="${total_price!}";
var onePrice="${total_price!}";
var send_cost="0";
<#if commodity_type == '01' >
   var strHtml="";
	strHtml+="<div class='fl'>运费</div>";
	strHtml+="<div class='fr fr_'>￥<span class='red' id='send_cost'>0</span></div>";
	$("#yunfei").html(strHtml);
</#if>

<#if commodity_type == '01' >
if($("#send_cost").html()=="包邮"){
	 send_cost="0";
}else{
	 send_cost=$("#send_cost").html().replace("￥","");
}
</#if>
price=FloatAdd(parseFloat(price),parseFloat(send_cost));
var commodity_type="${commodity_type!}";
var address_id="";
$("#totalPrice").html(price);
if(commodity_type == 01){
<#if sendAddress??>
address_id="${sendAddress.id!}";
</#if>
}
var slotId="";
<#if slotId??>
slotId="${slotId!}";
</#if>
var timeSlot="";
<#if timeSlot??>
timeSlot="${timeSlot!}";
</#if>
var ticket_id = "";
var mortgage_amount = "";
var that = "";
$(".ticket").on("click", function() {
	$(".ticket").removeClass("checked");
	$(this).addClass("checked");
	ticket_id=$(this).data("id");
	if(ticket_id==that){
		$(".ticket").removeClass("checked");
		that="";
		ticket_id="";
		mortgage_amount = "";
		$("#totalPrice").html(price);
	}else{
		that = $(this).data("id");
		ticket_id = $(this).data("id");
		mortgage_amount=$(this).data("value");
		var checkVal = FloatSub(price,mortgage_amount);
		if(parseFloat(checkVal)<0){
			checkVal = 0;
		}
		$("#totalPrice").html(checkVal);
	}
})

		submitOrder = function() {
		 if(commodity_type == 01){
			if(address_id=='' || address_id==undefined || address_id==null){
			   dialog('#ok',3000,"送货地址不能为空");
			   return;
	        }
	     }
			$(".btn_submit").removeAttr("onclick");
	        $(".btn_submit").removeClass("btn_red");
	        $(".btn_submit").addClass(".btn_gray");
	        $(".btn_submit").removeAttr("onclick");
			$.post("${ctx}/pay/createWXPayOrder",{
				mortgage_amount:mortgage_amount,
				ticket_id:ticket_id,
				commodity_id:"${id!}",
				totalPrice:price,
				onePrice:onePrice,
				version_id:"${version_id!}",
				countNum:"${countNum!}",
				type:"${type!}",
				address_id:address_id,
				commodity_type:"${commodity_type!}",
				timeSlot:timeSlot,
				slotId:slotId,
				send_cost:send_cost
			},function(data){
			 if(data.code==0){
					window.location.href="${ctx}/pay/aliPay?pay_money="+data.pay_money+"&order_id="+data.order_id+"&commodity_type=${commodity_type!}";
			 }else if(data.code==2){
					window.location.href="${ctx}/pay/accountPay?pay_money="+data.pay_money+"&order_id="+data.order_id+"&commodity_type=${commodity_type!}&ticket_id="+data.ticket_id+"&membership_discount="+data.membership_discount;
			 }else{
				    dialog('#ok',3000,data.msg);
			 }
			},'json'); 
		}
		
		$(".mod_addr").click(function(){
		window.location.href="${ctx}/mine/getAddr?version_id="+"${version_id!}"+"&countNum="+"${countNum!}"+"&price="+"${price!}"+"&type="+"${type!}"+"&id="+"${id!}"+"&forward_type=01"+"&is_order=01"+"&commodity_type=${commodity_type!}"+"&slotId=${slotId!}";
		})
		
});
</script>
</html>